package com.deep.test.designpattern.proxy;

import java.lang.reflect.Method;

/**
 * <p>Description:</p>
 * Created with IDEA
 * author:hudepin
 * createTime:2018/5/22 14:27
 */
public class PersonProxy implements DpInvocationHandler {
    //被代理的对象，把引用给保存下来
    private Person target;
    public Object getInstance(Person p){
        this.target = p;
        Class clazz = p.getClass();
        return DpProxy.newProxyInstance(new DpClassLoader(),clazz.getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆：我要给你找对象，现在已经拿到你的需求");
        System.out.println("开始物色");

        method.invoke(this.target,args);

        System.out.println("如果合适的话，就准备办事");

        return  null;
    }
}
